package com.loma.common.utils.util

import android.content.Context
import android.util.TypedValue

/**
 * Created by xiaojianjun on 2019-11-13.
 */
fun Context.dpToPx(  dp: Float): Float {
    return dp *  resources.displayMetrics.density
}

fun Context.pxToDp(  px: Float): Float {
    return px /  resources.displayMetrics.density
}

fun Context.pxToDp(  px: Int): Int {
    return (px /  resources.displayMetrics.density).toInt()
}

/**
 * sp转px
 *
 * @param spVal   sp值
 */
fun Context.spToDp(spVal: Float): Float = TypedValue.applyDimension(
    TypedValue.COMPLEX_UNIT_SP,
    spVal, resources.displayMetrics
)